Public Class DateList

    Public StartDate As DateTime
    Public EndDate As DateTime

    Public Sub New()

    End Sub

    Public Function ListYears(ByVal bShowPast As Boolean, ByVal bShowPresent As Boolean, ByVal bShowFuture As Boolean) As DataTable
        Dim dtRet As New DataTable
        Dim dcData As New DataColumn("Data")
        Dim dcValue As New DataColumn("Value")
        dtRet.Columns.Add(dcData)
        dtRet.Columns.Add(dcValue)

        Dim iStartYear As Integer = StartDate.Year
        Dim iEndYear As Integer = EndDate.Year
        Dim iCurrentYear As Integer = DateTime.Now.Year
        Dim i As Integer
        For i = iStartYear To iEndYear
            Dim bAddThisYear As Boolean = False
            If bShowPast Then
                If i < iCurrentYear Then
                    bAddThisYear = True
                End If
            End If
            If bShowPresent Then
                If i = iCurrentYear Then
                    bAddThisYear = True
                End If
            End If
            If bShowFuture Then
                If i > iCurrentYear Then
                    bAddThisYear = True
                End If
            End If
            If bAddThisYear Then
                Dim dr As DataRow = dtRet.NewRow()
                dr("Data") = i
                dr("Value") = i
                dtRet.Rows.Add(dr)
            End If
        Next
        Return dtRet
    End Function


    Public Function ListMonths(ByVal bShowPast As Boolean, ByVal bShowPresent As Boolean, ByVal bShowFuture As Boolean) As DataTable
        Dim dtRet As New DataTable
        Dim dcData As New DataColumn("Data")
        Dim dcValue As New DataColumn("Value")
        dtRet.Columns.Add(dcData)
        dtRet.Columns.Add(dcValue)

        Dim dtCurrent As DateTime = DateTime.Now()
        Dim dt As DateTime = StartDate
        Dim iMonthCount As Integer = 0

        Do While dt <= EndDate
            Dim bAddThisMonth As Boolean = False
            If bShowPast Then
                If dt < dtCurrent Then
                    bAddThisMonth = True
                End If
            End If
            If bShowPresent Then
                If dt.Month = dtCurrent.Month Then
                    bAddThisMonth = True
                End If
            End If
            If bShowFuture Then
                If dt > dtCurrent Then
                    bAddThisMonth = True
                End If
            End If

            If bAddThisMonth Then
                If iMonthCount < 12 Then
                    iMonthCount = iMonthCount + 1
                    Dim dr As DataRow = dtRet.NewRow()
                    dr("Data") = dt.Month.ToString() + " - " + dt.ToString("MMMM")
                    dr("Value") = dt.Month
                    dtRet.Rows.Add(dr)
                Else
                    Return dtRet
                End If
            End If
            dt = dt.AddMonths(1)
        Loop
        Return dtRet
    End Function
End Class
